﻿using System;
using System.Windows;
using System.Windows.Threading;

namespace CompiledExperience.WP7.Midnight
{
	public partial class MainPage
	{
		private DispatcherTimer timer;

		public MainPage()
		{
			InitializeComponent();

			Loaded += OnLoaded;
		}

		private void OnLoaded(object sender, RoutedEventArgs e)
		{
			timer = new DispatcherTimer
			{
				Interval = TimeSpan.FromSeconds(1)
			};

			timer.Tick += OnTick;

			timer.Start();
		}

		private void OnTick(object sender, EventArgs e)
		{
            var practiceM = DateTime.Today.AddDays(1).AddHours(7);
            var practiceA = DateTime.Today.AddDays(1).AddHours(14);
			var timeLeft = practiceM - DateTime.Now;
            var timeLeft2 = practiceA - DateTime.Now;
            
			Countdown.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);
            Countdown2.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft2.Hours, timeLeft2.Minutes, timeLeft2.Seconds);
		}
	}
}
